package dao

import (
	"context"
	"epai/internal/model"
	"gorm.io/gorm"
)

func GetSchedules(ctx context.Context, db *gorm.DB, uuid string, goodsId int, shopId int, scheduleType int) (*[]model.Schedule, error) {
	var schedules []model.Schedule
	query := db.WithContext(ctx)

	if uuid != "" {
		query = query.Where("uuid = ?", uuid)
	}
	if goodsId != 0 {
		query = query.Where("goods_id = ?", goodsId)
	}
	if shopId != 0 {
		query = query.Where("shop_id = ?", shopId)
	}
	if scheduleType != 0 {
		query = query.Where("schedule_type = ?", scheduleType)
	}

	if err := query.Find(&schedules).Error; err != nil {
		return nil, err
	}
	return &schedules, nil
}

func GetSchedulesInFullDays(ctx context.Context, db *gorm.DB, shopId string, scheduleType int8, days []string) ([]model.Schedule, error) {
	var schedules []model.Schedule
	err := db.WithContext(ctx).Model(&model.Schedule{}).Where("shop_id= ? and schedule_type= ? and full_date in ?", shopId, scheduleType, days).Find(&schedules).Error
	if err != nil {
		return nil, err
	}
	return schedules, nil
}
